<?php
class NewsCommendAction extends CommonAction {
    public function index() {
        $newsCommend = M('NewsCommend');
        //搜索模块
        parent::search(array(
            'user'=>'评论者',
        ));
        if(!isset($_GET['act'])) {
            parent::page($newsCommend->count());
            $allCommend = $newsCommend->field(array('id', 'content','content'=>'fcontent', 'user'))
                                      ->limit($this->limit)
                                      ->order('addtime DESC')
                                      ->select();
        } else if($_GET['act'] == 'search') {
            parent::page($newsCommend->where($this->map)->count());
            $allCommend = $newsCommend->field(array('id', 'content','content'=>'fcontent', 'user'))
                                      ->limit($this->limit)
                                      ->where($this->map)
                                      ->order('addtime DESC')
                                      ->select();
        }
        $this->assign('allcommend', $allCommend);
        $this->assign('empty', '<tr><td colspan="4">没有任何数据</td></tr>');
        $this->display();
    }

    public function delete() {
        $id = $this->_get('id');
        if(isset($id)) {
            $newsCommend = M('NewsCommend');
            if(!$newsCommend->where('id='.$id)->getField('id')) $this->error('不存在此评论!', 0);
            $map['id'] = $id;
            $newsCommend->where($map)->delete() ? $this->success('删除评论成功!', __URL__) : $this->error('系统出错，删除评论失败!', 0);
        }
    }

    public function mulDelete() {
        $ids = implode(',', $_POST['select']);
        if(!$ids) $this->error('请至少勾选一项!', 0);
        $newsCommend = M('NewsCommend');
        $map['id'] = array('in', $ids);
        $newsCommend->where($map)->delete() ? $this->success('批量删除评论成功!', __URL__) : $this->error('系统出错，批量删除评论失败!', 0);

    }



}

?>